/**
* Copyright 2016年8月24日 北京福富软件技术股份有限公司
* All Rights Reserved.
* 文件名称: ThreadCount.java  
* 初始作者：g.huangshg 
* 初始版本：V1.0.0   
* 完成日期： 2016年8月24日 
*/
package com.thread;

import java.util.concurrent.atomic.AtomicLong;

public class ThreadCount {
  public static void main(String[] args) {
    
    Thread[] threads=new Thread[10000];
    for (int i = 0; i < 10000; i++) {
      threads[i]=new AThread();
      threads[i].start();
    }
  }
}

class AThread extends Thread{

  @Override
  public void run() {
    System.out.println(MyCounter.calNum());
  }
  
}

class Counter{
   private static long num;
   public Counter(){
     synchronized (Counter.class) {
      num++;
    }
   }
   public static synchronized long calNum(){
     return num;
   }
}

class MyCounter{
  private static AtomicLong num=new AtomicLong();
  
  public static long calNum(){
    num.incrementAndGet();
    return num.get();
  }
}
